import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pornhub_app/components/no_more/no_data.dart';
import 'package:pornhub_app/components/no_more/no_more.dart';
import 'package:pornhub_app/components/original_favor_cell/widget.dart';
import 'package:pornhub_app/model/original_flavor_cell_model/original_flavor_cell_model.dart';

import 'controller.dart';

class OriginalFlavorListPage extends StatefulWidget {
  const OriginalFlavorListPage({super.key});

  @override
  State<OriginalFlavorListPage> createState() => _OriginalFlavorListPageState();
}

class _OriginalFlavorListPageState extends State<OriginalFlavorListPage> {
  final OriginalFlavorListController controller =
      Get.put(OriginalFlavorListController());

  @override
  void initState() {
    super.initState();
    controller.fetch();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<OriginalFlavorListController>(
      init: controller,
      builder: (controller) {
        return EasyRefresh(
          onRefresh: () async {
            controller.pagingController.refresh();
          },
          controller: controller.refreshController,
          child: PagedListView.separated(
            pagingController: controller.pagingController,
            builderDelegate: PagedChildBuilderDelegate<OriginalFlavorCellModel>(
              itemBuilder: (context, item, index) => Container(
                padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 20.w),
                child: OriginalFlavorCell(originalFlavor: item),
              ),
              noMoreItemsIndicatorBuilder: (context) {
                return const NoMore();
              },
              noItemsFoundIndicatorBuilder: (context) {
                return const NoData();
              },
            ),
            separatorBuilder: (context, index) => Container(
              height: 3.w,
              color: const Color(0xff181818),
            ),
          ),
        );
      },
    );
  }
}
